package com.antt.cn.test3;

import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.SeekBar;

import com.antt.cn.test3.utils.AntLog;
import com.antt.cn.test3.views.BsrView1;

import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Ant on 2017/5/2  14:20
 * <p>
 * <p>
 *
 * @version 1.0.0
 * @auther Ant
 */

public class Test01 extends AppCompatActivity implements BaseInterface, SeekBar.OnSeekBarChangeListener {
    @BindView(R.id.ac_test01_seek01)
    SeekBar seek1;
    @BindView(R.id.ac_test01_seek02)
    SeekBar seek2;
    @BindView(R.id.ac_test01_seek03)
    SeekBar seek3;
    @BindView(R.id.ac_test01_seek04)
    SeekBar seek4;
    @BindView(R.id.ac_test01_bsrview1)
    BsrView1 bsr;


    private Point[] points = new Point[4];

    private Random random = new Random(200);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_test01);
        ButterKnife.bind(this);

        initView();
        initData();
        initListener();
        AntLog.i("Ac onCreate()");
    }

    @Override
    protected void onStart() {
        super.onStart();
        AntLog.i("ac onStart()");
    }


    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        for (int i = 0, n = points.length; i < n; i++) {
            points[i] = new Point(0, 0);
        }
    }

    @Override
    public void initListener() {
        seek1.setOnSeekBarChangeListener(this);
        seek2.setOnSeekBarChangeListener(this);
        seek3.setOnSeekBarChangeListener(this);
        seek4.setOnSeekBarChangeListener(this);
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//        int radomNum = random.nextInt();
        int radomNum = 20;
        AntLog.i("progress==" + progress + ", radomNum==" + radomNum);
        switch (seekBar.getId()) {
            case R.id.ac_test01_seek01:
                points[0].set(progress, progress + radomNum);
                break;
            case R.id.ac_test01_seek02:
                points[1].set(progress, progress + random.nextInt());
                break;
            case R.id.ac_test01_seek03:
                points[2].set(progress, progress + random.nextInt());
                break;
            case R.id.ac_test01_seek04:
                points[3].set(progress, progress + random.nextInt());
                break;
        }
        bsr.setPoints(points);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
}
